package com.jzy.util;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class StringUtil extends StringUtils {

    /**
     * @param formatString
     * @return String
     * @Description: 格式化空字符串为'未知'
     * @author JIHW
     * @date 2016-8-3
     */
    public static String formatStringToUnknown(String formatString) {
        return isEmpty(formatString) ? "未知" : formatString;
    }

    public static String formatNullToEmpty(String formatString) {
        return null == formatString ? "" : formatString;
    }

    /**
     * @param params
     * @return String
     * @Description: 将LIST转化为SQL中（"",""）格式数据
     * @author JIHW
     * @date 2017-1-11
     */
    public static String formatListToString(List<String> params) {
        StringBuffer result = new StringBuffer();
        if (null != params && params.size() > 0) {
            if (isEmpty(result.toString()))
                result.append("(");
            for (String param : params) {
                result.append(param).append(",");
            }
        }

        return isNotEmpty(result.toString()) ? result.toString().substring(0, result.toString().length() - 1) + ")" : "";
    }

    /**
     * 将字符串转换成list
     * @param s
     * @return
     */
    public static List<String> stringConveList(String s) {
        String d[] = s.split(",");
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < d.length; i++) {
            list.add(d[i]);
        }
        return list;
    }

}